package hl.demosample.app.ext

import android.content.Context
import android.content.res.Resources

/*
* path: DemoSample 
* Author: 86133
* Create: 2021-06-02 16:58
* Changes (from 2021-06-02)
* Desc:
*/

fun dp2px(context: Context, dp: Float): Int {
    return (dp * context.resources.displayMetrics.density + 0.5f).toInt()
}

/**
 * dip转pix
 *
 * @param dpValue
 * @return
 */
fun dip2px(context: Context, dpValue: Float): Int {
    val scale = getResources(context).displayMetrics.density
    return (dpValue * scale + 0.5f).toInt()
}

/**
 * 获得资源
 */
fun getResources(context: Context): Resources {
    return context.resources
}